"""
特殊情况：如果结点不足3个，直接返回head

首先，初始化前一个节点和当前节点pre,cur=head, head.next

然后，如果cur.val==pre.val，则将前一个结点指向当前节点下一位，pre.next = cur.next,更新当前节点cur=cur.next
    如果cur.val!=pre.val，则两个指针同时后移pre, cur = pre.next, cur.next

接着，如果当前节点cur is none,返回head
"""
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if head is None or head.next is None:   # 表示有2个节点
            return head
        
        pre, cur = head, head.next

        while True:
            if cur.val == pre.val:
                pre.next = cur.next
                cur = cur.next
            else:
                pre, cur = pre.next, cur.next
            
            if cur is None:
                return head